﻿namespace Language.Utility
{
    internal static class Project
    {
        public static string FindRoot( string file )
        {
            EnvDTE.DTE dte = (EnvDTE.DTE)Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService( typeof( EnvDTE.DTE ) );

            EnvDTE.ProjectItem item = dte.Solution.FindProjectItem( file );

            EnvDTE.Project project = item?.ContainingProject;
            EnvDTE.Property scriptsRootProperty = project?.Properties.Item( "ScriptsRoot" );

            return scriptsRootProperty?.Value as string ?? string.Empty;
        }
    }
}
